import typing
import dataclasses

import coin.support.alarm.logic.alarm_generator as ag
import xunkemgmt.alarm.alarm_config_pb2 as ac_pb2
import xunkemgmt.service.alarm_service_pb2 as as_pb2


T = typing.TypeVar('T')
U = typing.TypeVar('U')


@dataclasses.dataclass
class AlarmCtorInfo(typing.Generic[T, U]):
  ctor_type: T
  config_type: U


alarm_ctor_info_map = {
    as_pb2.ABNORMAL_APPLICATION_ALARM: AlarmCtorInfo(
        ctor_type=ag.AbnormalApplicationAlarm,
        config_type=ac_pb2.AbnormalApplicationAlarmConfig),
    as_pb2.ABNORMAL_POSITION_ALARM: AlarmCtorInfo(
        ctor_type=ag.AbnormalPositionAlarm,
        config_type=ac_pb2.AbnormalPositionAlarmConfig),
    as_pb2.MULTI_PROCESS_ALARM: AlarmCtorInfo(
        ctor_type=ag.MultiProcessAlarm,
        config_type=ac_pb2.MultiProcessAlarmConfig),
    as_pb2.NO_ORDER_EVENT_ALARM: AlarmCtorInfo(
        ctor_type=ag.NoOrderEventAlarm,
        config_type=ac_pb2.NoOrderEventAlarmConfig),
    as_pb2.NO_PNL_BALANCE_ALARM: AlarmCtorInfo(
        ctor_type=ag.NoPnlBalanceAlarm,
        config_type=ac_pb2.NoPnlBalanceAlarmConfig),
    as_pb2.NO_STRATEGY_LOG_ALARM: AlarmCtorInfo(
        ctor_type=ag.NoStrategyLogAlarm,
        config_type=ac_pb2.NoStrategyLogAlarmConfig),
    as_pb2.ORDER_ERROR_ALARM: AlarmCtorInfo(
        ctor_type=ag.OrderErrorAlarm,
        config_type=ac_pb2.OrderErrorAlarmConfig),
    as_pb2.PENDING_ORDER_ALARM: AlarmCtorInfo(
        ctor_type=ag.PendingOrderAlarm,
        config_type=ac_pb2.PendingOrderAlarmConfig),
    as_pb2.RATE_LIMIT_ALARM: AlarmCtorInfo(
        ctor_type=ag.RateLimitAlarm,
        config_type=ac_pb2.RateLimitAlarmConfig),
    as_pb2.RETIRED_STRATEGY_ALARM: AlarmCtorInfo(
        ctor_type=ag.RetiredStrategyAlarm,
        config_type=ac_pb2.RetiredStrategyAlarmConfig),
    as_pb2.STRATEGY_STACK_ALARM: AlarmCtorInfo(
        ctor_type=ag.StrategyStackAlarm,
        config_type=ac_pb2.StrategyStackAlarmConfig),
    as_pb2.SYSTEM_CRITICAL_ERROR_ALARM: AlarmCtorInfo(
        ctor_type=ag.SystemCriticalErrorAlarm,
        config_type=ac_pb2.SystemCriticalErrorAlarmConfig),
    as_pb2.TOPIC_NOT_FOUND_ALARM: AlarmCtorInfo(
        ctor_type=ag.TopicNotFoundAlarm,
        config_type=ac_pb2.TopicNotFoundAlarmConfig),
}